package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnzz.site1255174697.ConstHost;
import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.activity.taobao.KindsListActivity;
import com.cnzz.site1255174697.model.RecommEntity;
import com.cnzz.site1255174697.view.XGridViewForScrollView;
import com.cqyanyu.yanyu.view.recyclerView.YViewHolder;
import com.squareup.picasso.Picasso;

/**
 *
 */
public class RecommHolder extends YViewHolder {

    protected XGridViewForScrollView tGridView;
    protected ImageView ivTubiao;
    protected TextView tvKindsName;
    private KindsGoodsGridAdapter textImgAdapter;
    private Context context;
    private RecommEntity recommEntity;

    public RecommHolder(View parent) {
        super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recom, null));
        context = parent.getContext();
        tGridView = (XGridViewForScrollView) itemView.findViewById(R.id.tGridView);
        ivTubiao = (ImageView) itemView.findViewById(R.id.iv_tubiao);
        tvKindsName = (TextView) itemView.findViewById(R.id.tv_kinds_name);
    }

    @Override
    public void onBindViewHolder(Object itemData) {
        super.onBindViewHolder(itemData);
        recommEntity = (RecommEntity) itemData;
        //首页分类
        if (recommEntity.getKindsList() != null) {
            textImgAdapter = new KindsGoodsGridAdapter(context, recommEntity.getKindsList());
            tGridView.setAdapter(textImgAdapter);
            tGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    context.startActivity(new Intent(context, KindsListActivity.class).putExtra("title", textImgAdapter.getItem(position).getName()).
                            putExtra("type", textImgAdapter.getItem(position).getKey_id()).putExtra("name", textImgAdapter.getItem(position).getPname()));
                }

            });
        }
        if (recommEntity.getTagList() != null) {
            Picasso.with(context).load(ConstHost.IMG_BASE_URL + recommEntity.getTagList().get(2).getIcon()).into(ivTubiao);
            tvKindsName.setText("向您推荐");
        }
    }
}
